/* 
 *  FileName: syschr.c - sysfs测试程序
 *
 *  Author: He Jingbo   jbhe@isoftstone.com
 *
 *  Date: Mon 25 Oct 2010 05:48:31 PM CST
 */

/* 创建结点/sys/devices/platform/syschr/syschrdev
 */sys下的结点只需要创建读/写函数
 */
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/platform_device.h>

static  struct platform_device *syschr_dev;

static ssize_t show_syschr(struct device *dev,
        struct device_attribute *attr, char *buffer, ssize_t count)
{
    printk("This is a test programmer.\n");
    return count;
}

DEVICE_ATTR(syschrdev, 0644, show_syschr, NULL);

static struct attribute *syschr_attrs[]=
{
    &dev_attr_syschrdev.attr,
    NULL
};

static struct attribute_group syschr_attr_group =
{
    .attrs = syschr_attrs,
};

int __init syschr_init(void)
{
    syschr_dev = platform_device_register_simple("syschr", -1, NULL, 0);
    if(IS_ERR(syschr_dev))
    {
        PTR_ERR(syschr_dev);
        printk("vms_init:error \n");
    }
    sysfs_create_group(&syschr_dev->dev.kobj, &syschr_attr_group);
    return 0;
}

void syschr_cleanup(void)
{
    sysfs_remove_group(&syschr_dev->dev.kobj, &syschr_attr_group);
    platform_device_unregister(syschr_dev);
    return;
}

module_init(syschr_init);
module_exit(syschr_cleanup);
MODULE_LICENSE("GPL");
